Step 5: Experimental Design

Goal: Build an interface to configure your experiment's parameters (like trial count and timing) and connect them to your code.

🎯 Goal: Design Your Experiment Parameters

This step teaches you to systematically configure your psychology experiment's timing, structure, and conditions. You'll learn to balance statistical power with participant engagement while following psychology research best practices.

What You'll Learn:

⭐ Our Example: Configuring the RPS Experiment

This interface allows you to change the parameters for our Rock-Paper-Scissors example. The settings you save here will be used in the next step. Test how different configurations change the feel of the experiment.

RPS Example Configuration

"Save" applies settings to the Step 6 demo. "Download" gives you a file for your own project.

πŸ“Š Live Preview & Configuration Info

⏱️ Experiment Duration

With your current settings, this experiment will take approximately: ~1 minute

This helps you plan reasonable experiment lengths for your participants.

πŸ—οΈ Build Your Own Configuration File

For your own research, a structured text file is the professional standard for managing experiment parameters. Below, we'll guide you through creating a config.json file for your experiment from Step 0.

A JSON (JavaScript Object Notation) file is a simple, human-readable format for storing structured dataβ€”think of it as a digital recipe card for your experiment.

Part 1: Generate Your Base Configuration

Use the following prompt with an AI assistant to create a starting config.json file. Make sure to provide the AI with the context of your research question and methodology from Step 0.

AI Prompt: Create Experiment Config

Based on the research study I've provided from Step 0, create a `config.json` file for my experiment. The file should include parameters for:

  • Timing: Key durations like feedback display time.
  • Structure: The total number of trials.
  • Custom Parameters: Any other unique variables relevant to my study's design.

Keep the JSON clean and well-structured.

After running the prompt, save the output into a new file named config.json in your project folder. We'll use this file in the next part.

Part 2: Use Your Configuration to Build the Experiment Logic

Now, provide the AI with your newly created config.json file and ask it to write the core logic for your experiment.

AI Prompt: Implement Experiment Logic

Using the provided `config.json`, write the JavaScript logic for my experiment. This should include:

  • Loading and parsing the configuration file.
  • Running a single trial of the experiment according to the parameters defined in the file.
  • Logging the data for each trial.

Example Configuration File

Your generated file will look something like this, but tailored to your specific study. For a more detailed example, see the RPS experiment's configuration.

config.json
{
  "experiment": {
    "title": "My Reaction Time Study",
    "version": "1.0"
  },
  "timing": {
    "feedbackDuration": 1000
  },
  "structure": {
    "experimentTrials": 50
  }
}

πŸ”§ Using Your Configuration

With a config.json file (or the RPS settings you saved to localStorage) in place, your experiment needs to load and apply those values at runtime. Here's a concise pattern you can adapt:

πŸ“„ Loading JSON Configuration

// Load configuration at experiment startup async function loadConfig() { try { const response = await fetch('config.json'); const config = await response.json(); // Apply timing settings experimentParams.trialDuration = config.timing.trialDuration; experimentParams.interTrialInterval = config.timing.interTrialInterval; // Apply structure settings experimentParams.totalTrials = config.structure.experimentTrials; experimentParams.practiceTrials = config.structure.practiceTrials; console.log('Configuration loaded:', config); } catch (error) { console.error('Failed to load config, using defaults:', error); } }

βš™οΈ Applying Configuration

// Use configuration to control experiment flow function startTrial() { // Use configured timing setTimeout(() => { hideStimulusAndCollectResponse(); }, config.timing.trialDuration); } function endTrial() { // Use configured inter-trial interval setTimeout(() => { if (config.display?.showProgress) { updateProgressBar(); } startNextTrial(); }, config.timing.interTrialInterval); }

πŸ”— Putting Results Together for Analysis

In Step 6, your experiment will generate a single JSON file for each participant, ready for analysis. This file should combine participant details, the session's configuration, and the trial-by-trial data.

Here is the recommended structure, which you will build toward in the next step. It has three top-level keys:

πŸ—‚οΈ Example Results Package

{
  "participant": {
    "name": "Alice",
    "age": 29
  },
  "configuration": {
    "numTrials": 30,
    "showProgress": true,
    "aiAlgorithm": "counter"
  },
  "trialData": [
    { "round": 1, "playerChoice": "Rock",     "aiChoice": "Paper",    "outcome": "loss" },
    { "round": 2, "playerChoice": "Paper",    "aiChoice": "Scissors", "outcome": "loss" }
    // … additional trials …
  ]
}

Your trialData objects can include any additional fields you log (e.g., reaction time, confidence ratings). Just make sure each trial is an object in this array.

πŸ“„ Helper Snippet (JavaScript)

In the next step, you will use a function like this to assemble and download the final results object:

// Build the results package at the end of the experiment function buildResultsPackage(config, trials, participant) { return { participant, // e.g., { name: 'Alice', age: 29 } configuration: config, trialData: trials }; } // This function will be called from your "Download Results" button function exportResults() { const participantInfo = { name: gameState.participantName, age: gameState.participantAge }; const resultsPackage = buildResultsPackage(gameConfig, gameState.trialData, participantInfo); // Helper to trigger browser download downloadJSON(resultsPackage, `results_${participantInfo.name || 'participant'}.json`); }

With this structure defined, you are ready to build the interactive logic in Step 6 that will generate these files.

πŸ“‹ Psychology Design Principles

⏰ Timing Considerations

  • Trial Duration: Long enough for valid responses, short enough to maintain attention
  • Inter-Trial Intervals: Prevent carry-over effects, allow mental reset
  • Total Duration: Most online experiments should be 5-15 minutes maximum
  • Break Scheduling: Every 50-100 trials for longer experiments

πŸ“Š Statistical Considerations

  • Power Analysis: More trials needed for small effect sizes
  • Individual Differences: Account for participant variability
  • Practice Effects: Include sufficient practice trials
  • Counterbalancing: Randomize order to control sequence effects

πŸ‘₯ Participant Experience

  • Feedback Strategy: When and how to provide performance feedback
  • Progress Indicators: Help with motivation but may bias behavior
  • Difficulty Curves: Gradual introduction prevents frustration
  • Engagement: Balance rigor with participant enjoyment

βœ… Step 5 Checklist